﻿using IDal;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dal
{
    public class UserDal:IUserDal
    {
        private UserDbContext db;

        public UserDal(UserDbContext db)
        {
            this.db = db;
        }
        public int Login(string name, string pwd)
        {
            IQueryable<UserInfo> list = db.userInfos;
            list = list.Where(x=>x.UserName.Equals(name));
            if(list.Count()>0)
            {
                list = list.Where(x => x.UserPwd.Equals(pwd));
                if (list.Count() > 0)
                {
                    return 2;
                }
                //密码错误
                return 3;
            }
            //用户不存在
            return 1;
        }

        public dynamic Show(int pageindex = 1, int pagesize = 3)
        {
            IQueryable<UserInfo> list = db.userInfos;
            return new
            {
                listcount = list.Count(),
                plist= list.OrderBy(x=>x.UserId).Skip((pageindex-1)*pagesize).Take(pagesize),
            };
        }
    } 
}
